package com.snut.viruscheck.config;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
public class AsyncTaskConfig implements AsyncConfigurer {
    @Override
    @Bean
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor threadPoolTaskExecutor=new ThreadPoolTaskExecutor ();
        threadPoolTaskExecutor.setCorePoolSize(10);    //线程数
        threadPoolTaskExecutor.setQueueCapacity(100);    //等待队列容量 ，线程数不够任务会等待
        threadPoolTaskExecutor.setMaxPoolSize(50);     // 最大线程数，等待数不够会增加线程数，直到达此上线  超过这个范围会抛异常
        threadPoolTaskExecutor.initialize();
        return threadPoolTaskExecutor;

    }

    @Override
    @Bean
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return null;
    }

//    @Async
//    public  void  checkExpireOrder(OrderInfo orderInfo  )   {
//        Date expireDate= DateUtil.addDays(orderInfo.getCreateTime(),1) ;
//        if (new Date().after(expireDate)){
//            updateProcessStatus(orderInfo.getId(), ProcessStatus.CLOSED);
//            paymentService.closePayment(orderInfo.getId());
//        }
//        return ;
//    }
//
//    public void closePayment(String orderId){
//        Example example=new Example(PaymentInfo.class);
//        example.createCriteria().andEqualTo("orderId",orderId);
//        PaymentInfo paymentInfo=new PaymentInfo();
//        paymentInfo.setPaymentStatus(PaymentStatus.ClOSED);
//        paymentInfoMapper.updateByExampleSelective(paymentInfo,example);
//
//    }
}

